package org.elanfox.intellicommunity.biz.repository.msg;

import org.elanfox.intellicommunity.biz.entity.msg.LocationMsgPO;
import org.elanfox.intellicommunity.data.base.base.JpaSearchableRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author allan
 * @version 1.0.0
 * @date 2019/12/19
 */
@Repository
public interface LocationMsgRepository extends JpaSearchableRepository<LocationMsgPO, Long> {
    LocationMsgPO findTopByUserIdOrderByCreateTimeDesc(Integer userId);

    @Query("update LocationMsgPO msg set msg.latest=false where msg.id=?1")
    @Modifying
    @Transactional
    void updateLatestTag(Long id);

    /**
     * 根据楼层id得到最新的消息
     *
     * @param structureId
     * @return
     */
    List<LocationMsgPO> findByLocatorInfo_StructureIdAndLatestIsTrue(Integer structureId);
}
